home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14357 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.8 KB

  1. Path: news.uh.edu!cosc19z5
  2. From: cosc19z5@Bayou.UH.EDU (Spasmo)
  3. Newsgroups: comp.lang.c,comp.unix.programmer
  4. Subject: Re: Q: '\n' character
  5. Followup-To: comp.lang.c,comp.unix.programmer
  6. Date: 13 Apr 1996 23:24:00 GMT
  7. Organization: University of Houston
  8. Message-ID: <4kpd2g$eeb@masala.cc.uh.edu>
  9. References: <4kj66f$k0o@ren.cei.net> <1996Apr11.192937.25676@sq.com> <829396473snz@genesis.demon.co.uk>
  10. NNTP-Posting-Host: bayou.uh.edu
  11. X-Newsreader: TIN [version 1.2 PL2]
  12.  
  13. Lawrence Kirby (fred@genesis.demon.co.uk) wrote:
  14. : In article <1996Apr11.192937.25676@sq.com> msb@sq.com "Mark Brader" writes:
  15.  
  16. [Snip]
  17.  
  18.  
  19. : >In the specific case of a string obtained from fgets(), we can be
  20. : >sure that if there is a newline then it is the last character.
  21. : >This leads to the alternative approach:
  22. : >
  23. : >  ptr = strchr (buffer, '\n');   /* or strrchr() */
  24. : >  if (ptr) *ptr = '\0';
  25.  
  26. Ok, I've got a question at this point.  Is it really proper to say
  27. if (ptr)?  From what I've read, NULL wasn't supposed to be guaranteed
  28. to work with true/false tests like the above, so the only safe way
  29. was if (ptr != NULL).  As a matter of fact, that's what Stroustrup
  30. mentioned in his C++ book as a reason for using 0 instead of the NULL
  31. pointer when using C++, so that true/false tests could be safely performed.
  32.  
  33. If I'm wrong please tell me since I've been sticking with ptr != NULL
  34. now for the very reason of safety.  I would love to go for a good old
  35. true/false test rather than a NULL comparison if in fact this is
  36. valid regardless of implementation.  I've learned to stay away from
  37. testing code and going with the results since different implementations
  38. have different behaviors at times so even if my own experience would
  39. have shown the true/false approach to work I still would have avoided
  40. it until I heard an official "yes it can be done, or no it can't".
  41.  
  42. [Snip]
  43.  
  44. : -- 
  45. : -----------------------------------------
  46. : Lawrence Kirby | fred@genesis.demon.co.uk
  47. : Wilts, England | 70734.126@compuserve.com
  48. : -----------------------------------------
  49.  
  50.  
  51. Thanks.
  52.  
  53.  
  54. --
  55.  
  56.                       .A.                        G-Force!  1 AM Houston Time
  57.                      AAAAA                       On the Cartoon Network!
  58.                     AAY:YAA   
  59.                     A':::`A                      This informative message was 
  60.                     :::::::                      brought to you by Spasmo.
  61.                     ::( )::   
  62.                     :::::::
  63.                     :::::::
  64.                     :::::::
  65.                     :::::::     
  66.   .A.          .do:::::::::::bo.          .A.
  67.   AAA       .:::::::::::::::::::::.       AAA
  68.  d:::::::::::::::::::::::::::::::::::::::::::b
  69.  Y:::::::::::::::::::::::::::::::::::::::::::Y 
  70.  `YjY       `:::::::|::|::|:::::::'       YjY' 
  71.                  `::|::|::|::'  
  72.                        |
  73.